package com.ruowei.modules.foodOrder.repository;

import com.ruowei.modules.foodOrder.domain.CourierChangeLog;

import org.springframework.data.jpa.repository.*;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.stereotype.Repository;

import java.time.Instant;
import java.util.Optional;

@Repository
public interface CourierChangeLogRepository extends JpaRepository<CourierChangeLog, Long> , QuerydslPredicateExecutor<CourierChangeLog> {

    @Query(nativeQuery = true, value = "select * from (select * from courier_change_log where courier_code = ?1 and update_time < ?2 order by update_time desc) as log limit 1")
    Optional<CourierChangeLog> getMerchantChange(String courierCode, Instant updateTime);
}
